<html ng-app="ionicApp">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
		<title></title>
		<link href="css/ionic.css" rel="stylesheet">
		<link rel="stylesheet" href="css/bangkeapp.css" />
		<script src="js/ionic.bundle.js"></script>
		<script src="js/base64.js"></script>
		<link rel="stylesheet" type="text/css" href="css/ionic-banner-tips.min.css">
		<script type="text/javascript" src="js/notice.banner.js"></script>
		<script src="mobile/constant.js"></script>
		<script src="mobile/register/factory.js"></script>
	</head>

	<body ng-controller="registerforapp" class="register">
		<div class="bar bar-header">
			<div class="h1 title" style="color:#fff">注册</div>
		</div>
		<div class="logo">
			<div></div>
		</div>
		<div class="content">
			<div class="list">
				<!--<label class="item item-input item-stacked-label">
		      	<span class="input-label">用户名</span>
		      	<input type="text" ng-model="register.membername">
		    </label>-->
		    <div class="item item-input-inset"><span style="display: inline-block;max-width:120px">用户名</span>
	          	<label class="item-input-wrapper">
	            		<input type="text" ng-model="register.membername">
	          	</label>
          	</div>
			<!--<label class="item item-input item-stacked-label">
		      	<span class="input-label">密码</span>
		      	<input type="password" ng-model="register.password">
		    </label>-->
		    <div class="item item-input-inset"><span style="display: inline-block;max-width:120px">密码</span>
	          	<label class="item-input-wrapper">
	            		<input type="password" ng-model="register.password">
	          	</label>
      		</div>
			<!--<label class="item item-input item-stacked-label">
		      	<span class="input-label">确认密码</span>
		      	<input type="password" ng-model="register.repassword">
		    </label>-->
		    <div class="item item-input-inset"><span>确认密码</span>
	          	<label class="item-input-wrapper">
	            		<input type="password" ng-model="register.repassword">
	          	</label>
      		</div>
			<!--<label class="item item-input item-stacked-label">
		     	<span class="input-label">推荐人ID</span>
		      	<input type="text" ng-model="register.reference">
		    </label>-->
	    		<div class="item item-input-inset"><span style="display: inline-block;max-width:120px">推荐人</span>
	          	<label class="item-input-wrapper" >
	            		<input type="text" ng-value="register.reference" readonly="readonly">
	          	</label>
      		</div>
		    <div class="item item-input-inset"><span style="display: inline-block;max-width:120px">身份证号</span>
	          	<label class="item-input-wrapper">
	            		<input type="text" ng-model="register.idcard">
	          	</label>
      		</div>
		<!--<label class="item item-input item-stacked-label">
	     	<span class="input-label">身份证号</span>
	      	<input type="text" ng-model="register.idcard">
	    </label>-->
	    		<div class="item item-input-inset"><span  style="display: inline-block;max-width:120px">手机号</span>
          		<label class="item-input-wrapper">
            			<input type="text" ng-model="register.tel">
          		</label>
        		</div>
			<!--<label class="item item-input item-stacked-label">	
	     		<span class="input-label">验证码</span>
	      		<input type="text" ng-model="register.verificationcode">
	    		</label>-->
	    		<div class="item item-input-inset"><span style="display: inline-block;max-width:120px">验证码</span>
	          	<label class="item-input-wrapper" style="max-width:160px;">
	            		<input type="text" ng-model="register.verificationcode" style="min-width:160px">
	          	</label>
          		<button class="button button-small button-energized" ng-bind="text" ng-disabled="isDisable" ng-click="getsmscode()"
          				style="display:inline-block; max-width: 120px; color:#fff !important; white-space: nowrap;">
          		</button>
      		</div>
		</div>
		<div class="padding">
			<button class="button button-block  button-energized" 
				style="color:#fff !important;" ng-click="tologin()">注册</button>
			</div>
		</div>
		<script>
			// 注册
			bangkeapp.controller('registerforapp', ["$scope", "registerService", "$interval",
				function($scope, registerService, $interval) {
					// 获取html的参数
					$scope.register = {};
					var url = location.search; //获取url中"?"符后的字串 
					var theRequest = new Object();
					if(url.indexOf("?") != -1) {
						var base = new Base64();
						var str = base.decode(url.substr(1));

						strs = str.split("&");
						for(var i = 0; i < strs.length; i++) {
							theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
						}
						$scope.register.reference = theRequest.reference;
					}

					$scope.smscode = "";
					$scope.text = "获取验证码";
					// 获取验证码
					$scope.getsmscode = function() {

						if(undefined == $scope.register.tel || "" == $scope.register.tel) {
							alert("手机号不能为空!");
							return false;
						}
						var myreg = /^1[1|2|3|4|5|6|7|8|9|0][0-9]{9}$/;
						if(!myreg.test($scope.register.tel)) {
							alert('不是有效手机号！');
							return false;
						}
						$scope.tel = $scope.register.tel;

						$scope.n = 60;
						$scope.text = $scope.n + "秒";
						$scope.isDisable = true;

						var time = $interval(function() {

							$scope.n--;
							$scope.text = $scope.n + "秒后可重新获取";
							if($scope.n == 0) {
								$interval.cancel(time);
								$scope.isDisable = false;
								$scope.text = "获取验证码";
							}

						}, 1000);

						registerService.getsmscode($scope.tel).then(function(result) {
							var data = result;
							if(data.Response.Header.ResponseCode == "M") {
								$scope.smscode = data.Response.Body.Response[0].smscode;
							} else {
								alert(data.Response.Header.MsgList[0].MsgContent + " 请重新获取验证码!");
							}
						}, function(error) {
							console.log("error!");
						}, function(progress) {

						});
					}

					// 跳转到修改查看会员信息界面
					$scope.tologin = function() {
						// 校验
						if($scope.smscode != $scope.register.verificationcode) {
							alert("验证码错误!");
							return false;
						}
						if(undefined == $scope.register.membername || "" == $scope.register.membername) {
							alert("用户名不能为空!");
							return false;
						}
						if(undefined == $scope.register.password || "" == $scope.register.password) {
							alert("密码不能为空!");
							return false;
						}
						if($scope.register.password.length < 8) {
							alert("密码必须大于8位!");
							return false;
						}
						if(undefined == $scope.register.repassword || "" == $scope.register.repassword) {
							alert("确认密码不能为空!");
							return false;
						}
						if(undefined == $scope.register.idcard || "" == $scope.register.idcard) {
							alert("身份证号不能为空!");
							return false;
						}
						if(undefined == $scope.register.tel || "" == $scope.register.tel) {
							alert("手机号不能为空!");
							return false;
						}
						if($scope.register.membername.length > 11) {
							alert("用户名长度不能大于11位!");
							return false;
						}

						registerService.register($scope.register).then(function(result) {
							var data = result;
							if(data.Response.Header.ResponseCode == "M") {
								window.location.href = "registerokForApp.html";
							} else {
								alert(data.Response.Header.MsgList[0].MsgContent);
							}
						}, function(error) {
							console.log("error!");
						}, function(progress) {

						});
					}
				}
			]);
		</script>
	</body>
</html>